<?php
namespace Admin\Controller;
use Common\Controller\AdminbaseController;

class ShopsizeController extends AdminbaseController{

    protected $shopsize_model;

    public function _initialize() {
        parent::_initialize();
        $this->shopsize_model = D("Common/ShopSize");
    }

    // 尺寸列表
    public function index(){
        $cats=$this->shopsize_model->select();
        $this->assign("slidecats",$cats);
        $this->display();
    }

    // 尺寸添加
    public function add() {
        $this->display();
    }

    // 尺寸添加提交
    public function add_post() {
        if (IS_POST) {
            if ($this->shopsize_model->create()!==false) {
                if ($this->shopsize_model->add()!==false) {
                    $this->success("添加成功！", U("shopsize/index"));
                } else {
                    $this->error("添加失败！");
                }
            } else {
                $this->error($this->shopsize_model->getError());
            }
        }
    }

    // 尺寸编辑
    public function edit(){
        $id= I("get.id",0,'intval');
        $slidecat=$this->shopsize_model->where(array('cid'=>$id))->find();
        $this->assign($slidecat);
        $this->display();
    }

    // 尺寸编辑提交
    public function edit_post(){
        if (IS_POST) {
            if ($this->shopsize_model->create()!==false) {
                if ($this->shopsize_model->save()!==false) {
                    $this->success("保存成功！", U("shopsize/index"));
                } else {
                    $this->error("保存失败！");
                }
            } else {
                $this->error($this->shopsize_model->getError());
            }
        }
    }

    // 尺寸删除
    public function delete(){
        $id = I("get.id",0,'intval');
        if ($this->shopsize_model->delete($id)!==false) {
            $this->success("删除成功！");
        } else {
            $this->error("删除失败！");
        }
    }

    // 隐藏
    public function ban(){
        $id = I('get.id',0,'intval');
        if ($id) {
            $rst = $this->shopsize_model->where(array('cid'=>$id))->save(array('cat_status'=>0));
            if ($rst) {
                $this->success("幻灯片隐藏成功！");
            } else {
                $this->error('幻灯片隐藏失败！');
            }
        } else {
            $this->error('数据传入失败！');
        }
    }

    // 启用
    public function cancelban(){
        $id = I('get.id',0,'intval');
        if ($id) {
            $result = $this->shopsize_model->where(array('cid'=>$id))->save(array('cat_status'=>1));
            if ($result) {
                $this->success("启用成功！");
            } else {
                $this->error('启用失败！');
            }
        } else {
            $this->error('数据传入失败！');
        }
    }
}